<?php
class EavResource
{
    public function __construct()
    {
        $model = new Zend_Db_Table_Abstract($this->_entityTableName);
        parent::__construct($model);
    }

    public function load(&$model, $value, $field = null)
    {
        $resourceModel = new Zend_Db_Table($this->_entityTableName);
        $select = $resourceModel->select();

        if($field) {
            $select->where($this->formatFieldToWhere($field),$value);
        } else {
            $select->where($this->formatFieldToWhere($this->_entityFieldId),$value);
        }
        $select->limit(1);
        $data = $resourceModel->fetchAll($select);

        $optionsModel = new Zend_Db_Table($this->_optionTableName);
        $options = $optionsModel->fetchAll();
        foreach ($options as $_option) {
            $model->setOriginalData($_option->code,getOptionValue($data,$_option));
        }

        $model->setPrimary($this->_entityFieldId);
        $model->setIsNew(false);

        return $this;
    }

    public function save(&$model)
    {
        
    }

    public function delete(&$model)
    {
        
    }

    protected function formatFieldToWhere($field)
    {
        return $this->_name.'.'.$field.' = ?';
    }
}